// _ajax_layouts
// _action
// _project_id
//
if(isset($_POST['_ajax_layouts']) ){
add_action('init', function (){
// $_GET = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
// $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
if(isset($_POST['_action']))
include(get_template_directory().'/_layouts/'.$_POST['_ajax_layouts'].'/_ajax_'.$_POST['_action'].'.php');
exit();
});
}
function _extras($string,$filters='email link'){
$c = $string;
if(preg_match('/br/',$filters) == true) $c = nl2br($c );
//br tm link trim[40]
if(preg_match('/trim/',$filters) == true){
$c = wp_trim_words($c,explode(']',explode('trim[',$filters)[1])[0]);
}
if(preg_match('/link/',$filters) == true){
$p = parse_url($c)['host'];
if($p){
$parse = str_replace('www.','',parse_url($c)['host']);
$c = ''.$parse.'';
}else{
if(preg_match('/email/',$filters) == true){
$regex = '/(\S+@\S+\.\S+)/';
$replace = '$1';
$c = preg_replace($regex, $replace, $c);
}
}
}
return $c;
}
$oddb_script[] = file_get_contents( get_template_directory().'/_layouts/_main_script.js') ;
$oddb_style[] = file_get_contents( get_template_directory().'/_layouts/_main_style.css') ;
function _layout($html, $attr = array(''), $get_vars = false){
$file = get_template_directory().'/_layouts/'.$html.'.html';
$content='';
$system = array(
'turl' => get_template_directory_uri(),
'path' => get_template_directory_uri().'/_layouts/'.$html.'/',
'loop' => '',
'site_name' => get_bloginfo('name') );
//echo '/_layouts/'.$html.'/_'.$html.'.php';
include( get_template_directory().'/_layouts/'.$html.'/_'.$html.'.php');
$file_js =get_template_directory().'/_layouts/'.$html.'/_script.js';
if( file_exists($file_js)) {
$script = str_replace( array('{path}','{turl}'),
array($system['path'],$system['turl']),
file_get_contents( $file_js) ) ;
if(!in_array($script, $GLOBALS['oddb_script']))
$GLOBALS['oddb_script'][] = $script;
}
$file_css =get_template_directory().'/_layouts/'.$html.'/_style.css';
if( file_exists($file_css)) {
$script = str_replace(
array('{path}','{turl}'),
array($system['path'],$system['turl']),
file_get_contents( $file_css) ) ;
if(!in_array($script, $GLOBALS['oddb_style']))
$GLOBALS['oddb_style'][] = file_get_contents( $file_css);
}
return $content;
}
function _oddb_layout_script(){
/*
$path = get_template_directory().'/blocks/';
$files = scandir(get_template_directory().'/blocks/');
foreach($files as $f){
if(strpos($f, '.js') !== false){
$script = file_get_contents($path.$f);
if(!in_array($script, $GLOBALS['oddb_script']))
$GLOBALS['oddb_script'][]= $script;
}
}
*/
echo '';
return;
}
add_action('wp_footer', '_oddb_layout_script');
function _oddb_layout_style(){
/*
$path = get_template_directory().'/blocks/';
$files = scandir(get_template_directory().'/blocks/');
foreach($files as $f){
if(strpos($f, '.css') !== false){
$script = file_get_contents($path.$f);
if(!in_array($script, $GLOBALS['oddb_style']))
$GLOBALS['oddb_style'][]= $script;
}
}
*/
$script = str_replace('{turl}',get_template_directory_uri(), implode("",$GLOBALS['oddb_style']) ) ;
echo '';
return;
}
add_action('wp_footer', '_oddb_layout_style');
?>
$cache_block= array(
'?wordfence_',
'wp-content_',
'?gf_page=up',
'_input_3_vu',
'?layout=adm',
'wp-admin_vu',
'wp-admin_us',
'wp-admin_ad',
'robots.txt',
'vuln.htm'
);
$name = str_replace('/','_',ltrim(rtrim(str_replace('?super_cache','',$_SERVER['REQUEST_URI']),'/'),'/'));
//var_dump($name);
if(!in_array(substr( $name, 0, 11 ), $cache_block)){
if( !(isset($_GET['super_cache']) && $_GET['super_cache'] == 'flush_all')){
add_action('template_redirect', function (){
ob_start('foo_buffer_callback');
}, 0);
add_action('shutdown', function (){
@ob_end_flush();
}, 1000);
function foo_buffer_callback($buffer){
$lang = substr( get_locale() ,0,2);
$file = get_template_directory().'/_cache/'.ODDB_FOLDER.'/';
$file_lang = get_template_directory().'/_cache/'.ODDB_FOLDER.'/'.$lang.'/';
$name = str_replace('/','_',ltrim(rtrim(str_replace('?super_cache','',$_SERVER['REQUEST_URI']),'/'),'/'));
// START----------
if(substr( $name, 0, 5 ) !== 'shop_' ){
if(!is_dir($file)) mkdir($file);
if(!is_dir($file_lang)) mkdir($file_lang);
// create hash
$file = hash('ripemd160', ($name?$name:'_')).'.html';
$f = $file_lang.$file;
$file_names= array( '6b5ce71caf94b71c13c9df1ab3f77c4dad8b6535.html',
'488e25f342129116be2ce380827d5bcf67ba5cc4.html',
'4854a2b5ff637f3a2c88c3b229a0c2edc22bce0a.html',
'a10ec04e9af4998c45ebd3f5921183385fff33dd.html'
);
if(in_array($file, $file_names)){
$myfile = fopen($f, "w");
$txt = str_replace('http://','https://',$buffer);
fwrite($myfile, $txt);
fclose($myfile);
}
}
// END----------
return $buffer;
}
}
}
//?super_cache=flush_all
add_action('init', function (){
if(isset($_GET['super_cache']) && $_GET['super_cache']== 'flush_all'){
$folder = get_template_directory().'/_cache/'.ODDB_FOLDER.'/';
$folder1 = get_template_directory().'/_cache/products/';
$folder2 = get_template_directory().'/_cache/SQL/';
$folder3 = get_template_directory().'/_cache/ODDB_FOLDER/';
$folder4 = get_template_directory().'/_cache/events/';
$folder5 = get_template_directory().'/_cache/lang/';
// add folders products/
exec('rm -rf '.$folder);
exec('rm -rf '.$folder1);
exec('rm -rf '.$folder2);
//exec('rm -rf '.$folder3);
exec('rm -rf '.$folder4);
exec('rm -rf '.$folder5);
mkdir(get_template_directory().'/_cache/'.ODDB_FOLDER.'/');
//mkdir(get_template_directory().'/_cache/products/');
//mkdir(get_template_directory().'/_cache/SQL/');
//echo 'SUCCESS';
//exit;
}
if(isset($_GET['super_cache']) && $_GET['super_cache']== 'flush' && isset($_GET['file'])){
// create languages too here...
// find other language too and delete them too
$folder = get_template_directory().'/_cache/'.ODDB_FOLDER.'/'.$_GET['file'];
exec('rm -rf '.$folder);
echo 'SUCCESS';
exit;
}
});
function convertSize( $bytes ){
$sizes = array( 'B', 'KB', 'MB', 'GB', 'TB' );
for( $i = 0; $bytes >= 1024 && $i < ( count( $sizes ) -1 ); $bytes /= 1024, $i++ );
return( round( $bytes, 2 ) . " " . $sizes[$i] );
}
function GetDirectorySize($path){
$bytestotal = 0;
$path = realpath($path);
if($path!==false && $path!='' && file_exists($path)){
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object){
$bytestotal += $object->getSize();
}
}
return convertSize($bytestotal);
}
function update_adminbar($wp_adminbar) {
$dir = '/';
$disk_free = disk_free_space($dir);
$disk_total = disk_total_space($dir);
$disk_used = $disk_total - $disk_free;
$disk_used_p = sprintf('%.2f',($disk_used / $disk_total) * 100);
$disk_free = convertSize($disk_free);
$disk_used = convertSize($disk_used);
$disk_total = convertSize($disk_total);
$loads = sys_getloadavg();
$core_nums = trim(shell_exec("grep -P '^processor' /proc/cpuinfo|wc -l"));
$load = round($loads[0]/($core_nums + 1)*100, 2);
$load_cpu = $load.'%';
$load_time = $loads[0].', '.$loads[1].', '.$loads[2];
$wp_adminbar->add_node([
'id' => 'disk_space',
'title' => 'SUPER CACHE',
'meta' => [
'target' => 'Disk space'
]
]);
$wp_adminbar->add_node([
'id' => 'data_aaa_server',
'title' => ''.$_SERVER['SERVER_ADDR'].'',
'parent' => 'disk_space',
]);
$wp_adminbar->add_node([
'id' => 'data_a_server',
'title' => 'Disk: '.ceil($disk_free).'/'.ceil($disk_total).'GB',
'parent' => 'disk_space',
]);
$wp_adminbar->add_node([
'id' => 'data_b_server',
'title' => 'Size: ' . GetDirectorySize(get_template_directory().'/_cache/'),
'parent' => 'disk_space',
]);
$wp_adminbar->add_node([
'id' => 'data_g_server',
'title' => 'Cores: '.$core_nums ,
'parent' => 'disk_space',
]);
$wp_adminbar->add_node([
'id' => 'data_c_server',
'title' => 'CPU: '.$load_cpu ,
'parent' => 'disk_space',
]);
$wp_adminbar->add_node([
'id' => 'data_d_server',
'title' => 'Load: '.$load_time ,
'parent' => 'disk_space',
]);
$wp_adminbar->add_node([
'id' => 'data_e_server',
'title' => 'Path: '.ODDB_FOLDER ,
'parent' => 'disk_space',
]);
$wp_adminbar->add_node([
'id' => 'data_f_server',
'title' => 'Timer: '.date('H:i:s',ODDB_TIMER) ,
'parent' => 'disk_space',
]);
$url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$wp_adminbar->add_node([
'id' => 'flush_cache',
'title' => 'FLUSH cache',
'parent' => 'disk_space',
'href' => $url.(strpos($url,'?') == false? "?":"&")."super_cache=flush_all",
'meta' => [
'target' => '_self'
]
]);
}
if(current_user_can('administrator'))
add_action('admin_bar_menu', 'update_adminbar', 999);
if($_SERVER['REQUEST_URI'] == '/shop/'){
add_action('init', function (){
wp_redirect('/store/');
exit;
});
}
add_filter('jpeg_quality', function ($quality) {
return 70;
},10,2);
add_image_size( 'small_300', 300 );
add_image_size( 'small_half', 450 );
add_image_size( 'medium_half', 500 );
add_image_size( 'thousand', 1000 );
add_image_size( 'high', 1300 );
add_image_size( 'higher', 2000 );
add_image_size( 'higher_half', 2300 );
add_image_size( 'retina', 2600 );
add_image_size( 'retina_full', 3000 );
add_action( 'init', function() {
remove_image_size( 'medium' );
add_image_size( 'medium', 300 );
remove_image_size( 'large' );
add_image_size( 'large', 1024 );
remove_image_size( 'custom-size' );
// add_image_size( 'custom-size', 700 );
});
add_filter( 'big_image_size_threshold', '__return_false' );
add_action('init', function () {
remove_image_size( 'shop_catalog' );
remove_image_size( 'woocommerce_thumbnail' );
remove_image_size( 'shop_single' );
remove_image_size( 'shop_thumbnail' );
remove_image_size( 'woocommerce_gallery_thumbnail' );
remove_image_size( 'woocommerce_single' );
remove_image_size( 'large' );
remove_image_size( '1536x1536' );
remove_image_size( '2048x2048' );
});
add_filter( 'jpeg_quality', function () {
return 80;
});
add_filter( 'big_image_size_threshold', '__return_false' );
function is_edition(){
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$edition_mode = (strpos($actual_link,"block-renderer")>0?true:false);
return $edition_mode;
}
function get_image_tag_new( $id, $alt, $title, $align, $size = 'medium' ) {
list( $img_src, $width, $height ) = image_downsize( $id, $size );
$hwstring = image_hwstring( $width, $height );
$title = $title ? 'title="' . esc_attr( $title ) . '" ' : '';
$size_class = is_array( $size ) ? implode( 'x', $size ) : $size;
$class = 'align' . esc_attr( $align ) . ' size-' . esc_attr( $size_class ) . ' wp-image-' . $id;
/**
* Filters the value of the attachment's image tag class attribute.
*x
* @since 2.6.0
*
* @param string $class CSS class name or space-separated list of classes.
* @param int $id Attachment ID.
* @param string $align Part of the class name for aligning the image.
* @param string|int[] $size Requested image size. Can be any registered image size name, or
* an array of width and height values in pixels (in that order).
*/
$class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size );
$html = '';
/**
* Filters the HTML content for the image tag.
*
* @since 2.6.0
*
* @param string $html HTML content for the image.
* @param int $id Attachment ID.
* @param string $alt Image description for the alt attribute.
* @param string $title Image description for the title attribute.
* @param string $align Part of the class name for aligning the image.
* @param string|int[] $size Requested image size. Can be any registered image size name, or
* an array of width and height values in pixels (in that order).
*/
return apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );
}
function linkify($string){
if(strpos($string, "http") !== false ){
$string= preg_replace("/(^|[\n ])([\w]*?)([\w]*?:\/\/[\w]+[^ \,\"\n\r\t<]*)/is", "$1$2$3", $string);
$string= preg_replace("/(^|[\n ])([\w]*?)((www)\.[^ \,\"\t\n\r<]*)/is", "$1$2$3", $string);
$string= preg_replace("/(^|[\n ])([\w]*?)((ftp)\.[^ \,\"\t\n\r<]*)/is", "$1$2$3", $string);
$string= preg_replace("/(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+)+)/i", "$1$2@$3", $string);
return($string);
}else{
return($string);
}
}
function load_header_scripts_css(){
wp_register_style('oddb_style', get_template_directory_uri() . '/style-main.css', array(), '2.0');
wp_enqueue_style('oddb_style'); // Enqueue it!
}
add_action('wp_print_scripts', 'load_header_scripts_css');
add_action( 'woocommerce_product_options_advanced', function (){
echo '